package com.example.demo.service.impl;

import java.util.List;
import java.util.UUID;

import org.activiti.engine.IdentityService;
import org.activiti.engine.ProcessEngine;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.example.demo.dao.LeaveMapper;
import com.example.demo.entity.LeaveInfo;
import com.example.demo.service.LeaveService;

@Service
public class LeaveServiceImpl implements LeaveService {

	@Autowired
	private LeaveMapper leaveMapper;
	
	@Autowired
	private ProcessEngine processEngine;
		
	
	
	
	
	

	@Override
	public void addLeaveAInfo(String userId,String msg) {
		LeaveInfo leaveInfo = new LeaveInfo();
		leaveInfo.setLeaveMsg(msg);
		leaveInfo.setUserId(userId);
		String id = UUID.randomUUID().toString();
		leaveInfo.setId(id);
		//新增一条记录至数据库中
		leaveMapper.insert(leaveInfo);
//		//设置流程发起人
		IdentityService  identityService = processEngine.getIdentityService();
		identityService.setAuthenticatedUserId(userId);
	}







	@Override
	public LeaveInfo getLeaveInfo(String leaveId) {
		
		return leaveMapper.getById(leaveId);
	}







	@Override
	public List<LeaveInfo> getLeaveInfoByUserId(String userId) {
		return leaveMapper.getByUserId(userId);
	}
	
	

	
	
	

}
